www.gusucode.com > 串口测试程序,用于调试rs485接口 串口通信的程序 > 串口测试程序,用于调试rs485接口 串口通信的程序/commtest/MPBase.cpp
// MPBase.cpp: implementation of the CMPBase class. // ////////////////////////////////////////////////////////////////////// #include "StdAfx.h" #include "MPBase.h" ////////////////////////////////////////////////////////////////////// // Construction/Destruction ////////////////////////////////////////////////////////////////////// CMPBase::CMPBase() { } CMPBase::~CMPBase() { } BYTE CMPBase::TranHexToBcd(BYTE data)//十六进制数转换为组合BCD码 { BYTE m_data; m_data = ((data / 10) << 4 ) + (data % 10); return m_data; } BYTE CMPBase::TranBcdToHex(BYTE data) { BYTE m_data; m_data = ((data >> 4) * 10 ) + (data & 0x0F); return m_data; } int CMPBase::GetCheckSum(BYTE *info, int info_len) { int init = 0x00; for (int i=0; i<info_len; i++) init += *(info+i); return BYTE(init & 0xFF); }